﻿using AutoMapper;
using CommunityToolkit.Mvvm.ComponentModel;
using FunasrSTT.Translate.Services;
using Prism.Events;
using Prism.Ioc;
using Prism.Mvvm;

namespace FunasrSTT.Translate.ViewModels;

/// <summary>
/// 视图模型
/// </summary>

public partial class ViewModelBase : ObservableObject
{
    /// <inheritdoc />
    public virtual string Title { get; set; } = string.Empty;

    /// <summary>
    /// 视图模型是否已经加载.
    /// </summary>
    protected bool IsLoaded { get; set; }

    protected readonly IMapper Mapper;
    protected readonly IContainerProvider Container;
    protected readonly Services.LanguageService LanguageService;
    protected readonly Services.DialogService DialogService;
    protected readonly IEventAggregator EventAggregator;
    public ViewModelBase() { }

    public ViewModelBase(
        IMapper mapper,
        IContainerProvider container,
        Services.LanguageService languageService,
        Services.DialogService dialogService,
        IEventAggregator eventAggregator)
    {
        Mapper = mapper;
        Container = container;
        LanguageService = languageService;
        DialogService = dialogService;
        EventAggregator = eventAggregator;
    }

    /// <summary>
    /// 本地化文本.
    /// </summary>
    /// <param name="key">文本键.</param>
    /// <param name="args">替换参数.</param>
    /// <returns>本地化文本.</returns>
    protected string L(string key, params object[] args)
    {
        return LanguageService.L(key, args);
    }

    /// <summary>
    /// 对象映射.
    /// </summary>
    /// <typeparam name="T">目标类型.</typeparam>
    /// <param name="source">源实例.</param>
    /// <returns>目标类型实例.</returns>
    protected T MM<T>(object source)
    {
        return Mapper.Map<T>(source);
    }

}
